﻿using System.Linq;
using cfg.card;
using cfg.pawn;
using kemocard.Scripts.Buff;
using kemocard.Scripts.Common;
using kemocard.Scripts.Module.Battle;
using kemocard.Scripts.Pawn;

namespace kemocard.Scripts.Card.Scripts;

public class C1() : BaseBuffCard("1");

public class C6() : BaseBuffCard("6");

public class C7() : BaseBuffCard("7");

public class C9() : BaseBuffCard("9");

public class C10() : BaseBuffCard("10");

public class C13() : BaseBuffCard("13");

public class C14() : BaseBuffCard("14");

public class C15() : BaseBuffCard("15");

public class C17() : BaseBuffCard("17")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        buff.TempValue = parent.RealTimeChain * 500;
    }
}

public class C19() : BaseBuffCard("19E")
{
    protected override void AfterAddBuff(BaseBattleCard parent)
    {
        var buff2 = StaticUtil.NewBuffOrNullById("19T", parent.User);
        if (buff2 == null) return;
        if (Mod is not { Teammates: not null }) return;
        foreach (var character in Mod.Teammates)
        {
            character.AddBuff(buff2);
        }
    }
}

public class C22() : BaseBuffCard("22");

public class C23() : BaseBuffCard("23");

public class C24() : BaseBuffCard("24")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        var count = parent.User.TempUsedCard.Count(card =>
            card.CardType == CardType.GUARD);

        buff.SpecialFlag = count >= 2;
    }
}

public class C25() : BaseBuffCard("25");

public class C29() : BaseBuffCard("29")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        buff.TempValue = parent.User.CurrentHealth * 0.1f;
    }

    protected override void AfterAddBuff(BaseBattleCard parent)
    {
        HealStruct heal = new()
        {
            Value = (int)parent.CalculateRealTimeValue(4000, [Tag.HEAL, Tag.WIND, Tag.AT]),
            Role = parent.User.Role,
            Attribute = parent.Attribute,
            Target = parent.Target,
            User = parent.User,
        };
        Mod?.DoHeal(heal);
    }
}

public class C30() : BaseBuffCard("30");

public class C34() : BaseBuffCard("34");

public class C35() : BaseBuffCard("35");

public class C36() : BaseBuffCard("36");

public class C37() : BaseBuffCard("37");

public class C38() : BaseBuffCard("38");

public class C39() : BaseBuffCard("39");

public class C40() : BaseBuffCard("40");

public class C44() : BaseBuffCard("44")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        buff.TempValue = parent.User.MaxHealth * 0.01f * (1 + parent.RealTimeChain);
    }
}

public class C45() : BaseBuffCard("45")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        if (parent.User.Deck.Count(c => (c.Attribute & (int)Attribute.DARK) >= 0) >= 6) buff.SpecialFlag = true;
    }
}

public class C46() : BaseBuffCard("46")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        if (parent.User.Deck.Count(c => (c.Attribute & (int)Attribute.DARK) >= 0) >= 6) buff.SpecialFlag = true;
    }
}

public class C49() : BaseBuffCard("49");

public class C51() : BaseBuffCard("51");

public class C52() : BaseBuffCard("52");

public class AcidWormBlocker() : BaseBuffCard("ACID_WORM_BLOCKER_E")
{
    protected override void AfterAddBuff(BaseBattleCard parent)
    {
        var buff = StaticUtil.NewBuffOrNullById("ACID_WORM_BLOCKER_T", parent.User);
        if (buff == null) return;
        parent.User.AddBuff(buff);
    }
}

public class AcidWormGuard() : BaseBuffCard("ACID_WORM_GUARD_E")
{
    protected override void AfterAddBuff(BaseBattleCard parent)
    {
        Mod?.Teammates.ForEach(t =>
        {
            var buff = StaticUtil.NewBuffOrNullById("ACID_WORM_GUARD_T", parent.User);
            if (buff == null) return;
            t.AddBuff(buff);
        });
    }
}

public class BatEarthGuard() : BaseBuffCard("BAT_EARTH_GUARD");

public class BatEarthBlocker() : BaseBuffCard("BAT_EARTH_BLOCKER");

public class BatEarthSupport() : BaseBuffCard("BAT_EARTH_SUPPORT");

public class RoverTyphoonSupport() : BaseBuffCard("ROVER_TYPHOON_SUPPORT");

public class RoverTyphoonGuard() : BaseBuffCard("ROVER_TYPHOON_GUARD");

public class RoverTyphoonBlocker() : BaseBuffCard("ROVER_TYPHOON_BLOCKER")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        if (parent.RealTimeChain >= 3)
        {
            parent.Target = Mod?.Enemies.ToList<BasePawn>();
        }
    }
}

public class SnStarGuard() : BaseBuffCard("SN_STAR_GUARD");

public class SnStarSupport() : BaseBuffCard("SN_STAR_SUPPORT")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        buff.TempValue = parent.CalculateRealTimeValue(1, [Tag.HEAL, Tag.LIGHT, Tag.AT]);
    }
}

public class FesZellerGuard() : BaseBuffCard("FES_ZELLER_GUARD")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        if (parent.User.TempUsedCard.Count(c => c.CardType == CardType.GUARD) >= 2)
        {
            buff.SpecialFlag = true;
        }
    }
}

public class FesZellerBlocker() : BaseBuffCard("FES_ZELLER_BLOCKER");

public class SnSethGuard() : BaseBuffCard("SN_SETH_GUARD");

public class SnSethBlocker() : BaseBuffCard("SN_SETH_BLOCKER");

public class SnSethSupport() : BaseBuffCard("SN_SETH_SUPPORT")
{
    protected override void AfterAddBuff(BaseBattleCard parent)
    {
        if (parent.User.TempUsedCard.Count(c => c.CardType == CardType.SUPPORT) < 2) return;
        HealStruct heal = new()
        {
            Value = (int)parent.CalculateRealTimeValue(5000, [Tag.HEAL, Tag.LIGHT, Tag.AT]),
            Role = parent.User.Role,
            Attribute = parent.Attribute,
            Target = parent.Target,
            User = parent.User,
        };
        Mod?.DoHeal(heal);
    }
}

public class C53() : BaseBuffCard("53");

public class C55() : BaseBuffCard("55");

public class C56() : BaseBuffCard("56");

public class C57() : BaseBuffCard("57");

public class C58() : BaseBuffCard("58");

public class C59() : BaseBuffCard("59");

public class C61() : BaseBuffCard("61");

public class C62() : BaseBuffCard("62");

public class C63() : BaseBuffCard("63");

public class C64() : BaseBuffCard("64");

public class C66() : BaseBuffCard("66");

public class C67() : BaseBuffCard("67");

public class SlimeEarthGuard() : BaseBuffCard("SLIME_EARTH_GUARD");

public class SlimeEarthBlocker() : BaseBuffCard("SLIME_EARTH_BLOCKER")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        buff.SpecialFlag = parent.RealTimeChain >= 2;
    }
}

public class SwanGuard() : BaseBuffCard("SWAN_GUARD");

public class SwanSupport() : BaseBuffCard("SWAN_SUPPORT");

public class LizEarthAttacker() : BaseBuffCard("LIZ_EARTH_ATTACKER")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        buff.SpecialFlag = parent.User.TempUsedCard.Count >= 2;
    }
}

public class LizEarthGuard() : BaseBuffCard("LIZ_EARTH_GUARD");

public class SciSantosA() : BaseBuffCard("SCI_SANTOS_A_E")
{
    protected override void AfterAddBuff(BaseBattleCard parent)
    {
        var buff = StaticUtil.NewBuffOrNullById("SCI_SANTOS_A_T", parent.User);
        if (buff == null) return;
        parent.User?.AddBuff(buff);
    }
}

public class SciSantosG() : BaseBuffCard("SCI_SANTOS_G");

public class SsRainsG() : BaseBuffCard("SS_RAINS_G");

public class FortisCarterG() : BaseBuffCard("FORTIS_CARTER_G");

public class FortisCarterB() : BaseBuffCard("FORTIS_CARTER_B");

public class KnightCollinG() : BaseBuffCard("KNIGHT_COLLIN_G")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        buff.SpecialFlag =
            parent.User.TempUsedCard.Count(c => c.CardType == CardType.GUARD) >= 2;
    }
}

public class KnightCollinB() : BaseBuffCard("KNIGHT_COLLIN_B")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        if (parent.RealTimeChain >= 3)
        {
            parent.Target = Mod?.Enemies.ToList<BasePawn>();
        }
    }
}

public class FortisZellerG() : BaseBuffCard("FORTIS_ZELLER_G");

public class KnightForgeB() : BaseBuffCard("KNIGHT_FORGE_B")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        buff.SpecialFlag = parent.User.Power >= 75;
        if (buff.SpecialFlag)
        {
            parent.User.Power -= 75;
        }
    }
}

public class FlowerMerlinG() : BaseBuffCard("FLOWER_MERLIN_G");

public class FlowerMerlinB() : BaseBuffCard("FLOWER_MERLIN_B")
{
    protected override void AfterAddBuff(BaseBattleCard parent)
    {
        parent.User.Power += 15;
    }
}

public class FlowerMerlinS() : BaseBuffCard("FLOWER_MERLIN_S")
{
    protected override void AfterAddBuff(BaseBattleCard parent)
    {
        HealStruct heal = new()
        {
            Value = 1,
            Role = parent.User.Role,
            Attribute = parent.Attribute,
            Target = [parent.User],
            User = parent.User,
        };
        Mod?.DoHeal(heal);
    }
}

public class ValentineSsG() : BaseBuffCard("VALENTINE_SS_G")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        buff.TempValue = parent.RealTimeChain;
    }
}

public class ValentineSsB() : BaseBuffCard("VALENTINE_SS_B")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        buff.TempValue = parent.RealTimeChain;
    }
}

public class MetalZcG() : BaseBuffCard("METAL_ZC_G");

public class SciRainsG() : BaseBuffCard("SCI_RAINS_G")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        if (parent.User.TempUsedCard.Count(card =>
                card.CardType == CardType.GUARD) >= 2)
        {
            parent.Target = Mod?.Teammates.ToList<BasePawn>();
        }
    }
}

public class SciRainsB() : BaseBuffCard("SCI_RAINS_B")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        buff.SpecialFlag = (parent.User.Race & (int)Race.FELIDAE) > 0;
    }
}

public class BalladTyphoonA() : BaseBuffCard("BALLAD_TYPHOON_A")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        var count = parent.User.TempUsedCard.Count;

        var rate = count switch
        {
            >= 3 => 0.05f,
            >= 2 => 0.03f,
            _ => 0.01f
        };

        buff.TempValue = rate * parent.User.CurrentHealth;
    }
}

public class BalladTyphoonG() : BaseBuffCard("BALLAD_TYPHOON_G");

public class BalladTyphoonB() : BaseBuffCard("BALLAD_TYPHOON_B")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        buff.TempValue = parent.User.CurrentHealth * 0.1f;
    }
}

public class BalladTyphoonS() : BaseBuffCard("BALLAD_TYPHOON_S")
{
    protected override void AfterAddBuff(BaseBattleCard parent)
    {
        HealStruct heal = new()
        {
            Value = (int)parent.CalculateRealTimeValue(1, parent.Tags),
            Role = parent.User.Role,
            Attribute = parent.Attribute,
            Target = [parent.User],
            User = parent.User,
        };
        Mod?.DoHeal(heal);
    }
}

public class OccultismTripleG() : BaseBuffCard("OCCULTISM_T_G")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        var count = 0;
        Mod?.Teammates.ForEach(teammate =>
        {
            if ((teammate.Race | (int)Race.UNKNOWN) > 0 || (teammate.Race | (int)Race.RABMOU) > 0 ||
                (teammate.Race | (int)Race.FELIDAE) > 0)
            {
                count++;
            }
        });
        buff.SpecialFlag = count >= 2;
    }
}

public class OccultismTripleS() : BaseBuffCard("OCCULTISM_T_S")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        var count = 0;
        Mod?.Teammates.ForEach(teammate =>
        {
            if ((teammate.Race | (int)Race.UNKNOWN) > 0 || (teammate.Race | (int)Race.RABMOU) > 0 ||
                (teammate.Race | (int)Race.FELIDAE) > 0)
            {
                count++;
            }
        });
        if (count >= 2)
        {
            parent.Target = Mod?.Teammates.ToList<BasePawn>();
        }

        buff.SpecialFlag = parent.RealTimeChain >= 3;
    }
}

public class ChivalryFcG() : BaseBuffCard("CHIVALRY_FC_G");

public class ChivalryFcB() : BaseBuffCard("CHIVALRY_FC_B");

public class ChivalryFcS() : BaseBuffCard("CHIVALRY_FC_S")
{
    protected override void AfterAddBuff(BaseBattleCard parent)
    {
        HealStruct heal = new()
        {
            Value = (int)parent.CalculateRealTimeValue(7500, 0, 0, 2.5f),
            Role = parent.User.Role,
            Attribute = parent.Attribute,
            Target = [parent.User],
            User = parent.User,
        };
        Mod?.DoHeal(heal);
    }
}

public class WaiterCollinG() : BaseBuffCard("WAITER_COLLIN_G");

public class WaiterCollinB() : BaseBuffCard("WAITER_COLLIN_B");

public class JamRzA() : BaseBuffCard("JAM_RZ_A")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        buff.SpecialFlag = parent.User.TempUsedCard.Count(c =>
            (c.Attribute | (int)Attribute.WATER) > 0 || (c.Attribute | (int)Attribute.FIRE) > 0) >= 2;
    }
}

public class JamRzG() : BaseBuffCard("JAM_RZ_G")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        buff.SpecialFlag = parent.RealTimeChain >= 3;
    }
}

public class JamRzB() : BaseBuffCard("JAM_RZ_B");

public class SwordCollinA() : BaseBuffCard("SWORD_COLLIN_A");

public class SwordCollinG() : BaseBuffCard("SWORD_COLLIN_G")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        buff.SpecialFlag = parent.User.TempUsedCard.Count(c => c.CardType == CardType.GUARD) >= 2;
    }
}

public class SwordCollinB() : BaseBuffCard("SWORD_COLLIN_B");

public class SwordCollinS() : BaseBuffCard("SWORD_COLLIN_S");

public class SwordRainsG() : BaseBuffCard("SWORD_RAINS_G");

public class SwordRainsB() : BaseBuffCard("SWORD_RAINS_B");

public class OnsenTyphoonG() : BaseBuffCard("ONSEN_TYPHOON_G");

public class OnsenTyphoonB() : BaseBuffCard("ONSEN_TYPHOON_BE")
{
    protected override void AfterAddBuff(BaseBattleCard parent)
    {
        if (parent.RealTimeChain < 3) return;
        var buff = StaticUtil.NewBuffOrNullById("ONSEN_TYPHOON_BT", parent.User);
        if (buff == null) return;
        parent.User.AddBuff(buff);
    }
}

public class OnsenSethB() : BaseBuffCard("ONSEN_SETH_B")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        buff.TempValue = parent.User.CurrentHealth * 0.1f;
    }
}

public class OnsenSethS() : BaseBuffCard("ONSEN_SETH_S")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        var heal = new HealStruct()
        {
            Value = (int)parent.CalculateRealTimeValue(2000, parent.Tags),
            Role = parent.User.Role,
            Attribute = parent.Attribute,
            Target = Mod?.Teammates.ToList<BasePawn>(),
            User = parent.User,
        };
        Mod?.DoHeal(heal);
    }
}

public class OnsenStarG() : BaseBuffCard("ONSEN_STAR_G");

public class OnsenStarB() : BaseBuffCard("ONSEN_STAR_B");

public class OnsenStarS() : BaseBuffCard("ONSEN_STAR_S")
{
    protected override void AfterAddBuff(BaseBattleCard parent)
    {
        if (parent.User.Heal < 15000) return;
        var heal = new HealStruct()
        {
            Value = (int)parent.CalculateRealTimeValue(2000, 0, 0, 1.2f),
            Role = parent.User.Role,
            Attribute = parent.Attribute,
            Target = Mod?.Teammates.ToList<BasePawn>(),
            User = parent.User,
        };
        Mod?.DoHeal(heal);
    }
}

public class OnsenRainsA() : BaseBuffCard("ONSEN_RAINS_A")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        buff.SpecialFlag = parent.User.PAttack >= 50000;
    }
}

public class OnsenRainsG() : BaseBuffCard("ONSEN_RAINS_G")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        if (parent.User.TempUsedCard.Count(c => c.CardType == CardType.GUARD) >= 2)
        {
            parent.Target = Mod?.Teammates.ToList<BasePawn>();
        }
    }
}

public class OnsenRainsB() : BaseBuffCard("ONSEN_RAINS_B")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        buff.SpecialFlag = parent.User.Power >= 50;
    }
}

public class AllegoryTpA() : BaseBuffCard("ALLEGORY_TP_A")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        buff.TempValue = parent.User.MaxHealth * 0.01f * parent.RealTimeChain;
    }
}

public class AllegoryTpG() : BaseBuffCard("ALLEGORY_TP_G");

public class AllegoryTpS() : BaseBuffCard("ALLEGORY_TP_S");

public class AllegorySethG() : BaseBuffCard("ALLEGORY_SETH_G")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        if (parent.User.Power < 20) return;
        parent.User.Power -= 20;
        buff.SpecialFlag = true;
    }
}

public class AllegorySethB() : BaseBuffCard("ALLEGORY_SETH_B")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        buff.SpecialFlag = parent.User.Deck.Count(c => (c.Attribute & (int)Attribute.WIND) > 0) >= 6;
    }
}

public class AllegorySethS() : BaseBuffCard("ALLEGORY_SETH_S")
{
    protected override void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
        if (parent.User.Power < 40) return;
        parent.User.Power -= 40;
        buff.SpecialFlag = true;
    }
}

public class HalloweenEllisG() : BaseBuffCard("HALLOWEEN_ELLIS_GS")
{
    protected override void AfterAddBuff(BaseBattleCard parent)
    {
        var buff = StaticUtil.NewBuffOrNullById("HALLOWEEN_ELLIS_GT", parent.User);
        if (buff == null) return;
        Mod?.Teammates.ForEach(t =>
        {
            var tempBuff = (BaseBuff)buff.Clone();
            t.AddBuff(tempBuff);
        });
    }
}

public class HalloweenEllisB() : BaseBuffCard("HALLOWEEN_ELLIS_B");

public class HalloweenEllisS() : BaseBuffCard("HALLOWEEN_ELLIS_S");